package servlet.user;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLDecoder;
import java.sql.SQLException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.commons.lang3.StringUtils;

import dao.UserDao;

public class QueryRecordAmountServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7376305558968241690L;

	public QueryRecordAmountServlet() {
		super();
	}

	public void destroy() {
		super.destroy();
	}

	
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("application/json;charset=utf-8");
		PrintWriter out = response.getWriter();
		// String dateSearch = request.getParameter("dateSearch");
		String softName = request.getParameter("softName");
		String startDate = request.getParameter("startDate");
		String endDate = request.getParameter("endDate");

		JSONObject jsonObject = new JSONObject();
		UserDao userDao = null;
		
		try {
			userDao = new UserDao();
			Map<String, Map<String, String>> mapm = userDao.queryRecordAmount(softName, startDate, endDate);
			if(mapm != null && mapm.size() > 0) {
				jsonObject.put("retCode", "1");
				jsonObject.put("recordAmounts", JSONObject.fromObject(mapm));
			} else {
				jsonObject.put("retCode", "0");
				jsonObject.put("desc", "无记录");
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
			jsonObject.put("retCode", "0");
			jsonObject.put("desc", "QueryRecordAmountServlet Exception");
		} finally {
			out.print(jsonObject.toString());
			out.close();
		}
		
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	
	public void init() throws ServletException {
	}

}
